#include "Stack.h"

//Stack::Stack(int x)
//{
//	_a = (int*)malloc(sizeof(int) * x);
//	_capacity = x;
//	_top = 0;
//}

Stack::Stack()
{
	_a = nullptr;
	_capacity = 0;
	_top = 0;
}

void Stack::Push(int x)
{
	if (_capacity == _top)
	{
		int newcapacity = _a == nullptr ? 4 : 2 * _capacity;
		int* tem = (int*)malloc(sizeof(int) * newcapacity);
		if (tem == nullptr)
		{
			perror("malloc fail");
			return;
		}
		_a = tem;
		_a[_top++] = x;
		_capacity = newcapacity;
	}
	else
	{
		_a[_top++] = x;
	}
}

int Stack::Top()
{
	return _a[_top - 1];
}

Stack::~Stack()
{
	free(_a);
	_capacity = 0;
	_top = 0;
}

void Stack::Pop()
{
	assert(_top > 0);
	_top--;
}



Data::Data()
{
	cout << "Data()" << endl;
	_year = 1;
	_month = 1;
	_day = 1;
}

//Data::Data(int year, int month, int day)
//{
//	_year = year;
//	_month = month;
//	_day = day;
//}

void Data::Print()
{
	cout << _year << "-" << _month << "-" << _day << endl;
}
